<form class="layui-form seller-form"  action="">
<div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">状态：</label>
            <div class="layui-input-inline seller-inline-2" >
                <select name="status" lay-verify="">
                    <option value=""></option>
                    <option value="1">未读</option>
                    <option value="2">已读</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">起止时间：</label>
            <div class="layui-input-inline seller-inline-6">
                <input  type="text" name="date" value="" id="date" placeholder="请输入起止时间" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="*"><i class="iconfont icon-chaxun"></i>筛选</button>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="message" lay-filter="test"></table>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate', 'table'], function(){
        //时间插件
        layui.laydate.render({
            elem: '#date',
            range: '到',
            type: 'datetime'
        });
        //获取列表数据
        layui.table.render({
            elem: '#message',
            height: 'full-330',
            cellMinWidth: '80',
            page: 'true',
            limit: '20',
            url: "{:url('MessageCenter/message')}?_ajax=1",
            id: 'message',
            method: 'post',
            cols: [[
                {field:'id', width:140, title:'ID', align:'center'},
                {field:'status', width:100, title:'状态', align:'center'},
                {field:'content', title:'内容'},
                {field:'ctime', width:180, title:'时间', align:'center'},

                {field:'operating', title:'操作', width:150, align:'center',templet:function(data){
                    var html = '';
                    html += '<a  class="layui-btn layui-btn-xs option-view layui-btn-primary" data-id="' + data.id + '">明细</a>';
                    html += '<a  class="layui-btn layui-btn-xs option-del" data-id="' + data.id + '">删除</a>';
                    return html;
                }}
            ]]
        });

        //搜索操作
        layui.form.on('submit(*)', function(data){
            layui.table.reload('message', {
                where: data.field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //查看操作
        $(document).on('click', '.option-view', function(){
            $.ajax({
                type:'get',
                url: "{:url('MessageCenter/messageView')}",
                data:'id='+$(this).attr('data-id'),
                success:function(e){
                    if(e.status){
                        layer.open({
                            type: 1,
                            skin: 'layui-layer-rim', //加上边框
                            area: ['420px', '240px'], //宽高
                            content: "<div style='padding:20px;'>" +e.data.content+ "</div>"
                        });
                    }else{
                        layer.msg(e.msg);
                    }

                }
            });
        });
        //删除操作
        $(document).on('click', '.option-del', function(){
            $.ajax({
                type:'get',
                url: "{:url('MessageCenter/messageDel')}",
                data:'id='+$(this).attr('data-id'),
                success:function(e){
                    layer.msg(e.msg);
                    if(e.status){
                        layui.table.reload('message');
                    }

                }
            });
        });
    });
</script>
